<?php

namespace App\Http\Controllers\Live;

use App\Http\Controllers\Controller;
use App\Jobs\RunDBCreateJob;
use App\Models\Live\LiveGroupModel;
use App\Models\Live\ShopMemberModel;
use App\Models\Shop;
use App\Models\ShopHost;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use MongoDB\Client;

class ActivityController extends Controller
{
    const REDIS_PREFIX_GROUP_POINTS="allenapi_group_points_";
    const REQUEST_API_RATE_TIMEOUT=10;
    const POINTS_SEND_LIST_RESET_SECONDS_DELAY=60*5;
    private function validateToken($token){
        $v=!empty($token);
        return $v;
    }
    public static function extractToken($token){
        if(strlen($token)>30){
            $token=ShopController::extractToken($token);
            if(!is_int($token)){
                return null;
            }
        }
        return $token;
    }
    public function generateToken(Request $request){

        $params=$request['params']??null;
        if(empty($params)){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'error params'
                ]
            );
        }
        $token=Hash::make($params);
        return response()->json(
                [
                    'code'=>0,
                    'msg'=>'success',
                    'data'=>$token
                ]
        );
    }
    public function refreshRoomList(Request $request){
        $rooms=ShopController::getLiveRooms(true);
        return response()->json([
            'code'=>0,
            'msg'=>'success',
            'data'=>$rooms
        ]);
    }
    public function onLiveRoomSendMsg(Request $request){
      $token=$request['token'];
      if($this->validateToken($token)){
        $token=$this->extractToken($token);
        if(empty($token)){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'认证解包异常'
                ]
            );
        }
        $member_id=$token;
        $oprate_type=$request['oprate_type']??'comment';
        $room_id=$request['room_id']??null;
        $data=[
            "room_id"=>$room_id,
            "member_id"=>$member_id,
            "oprate_type"=>$oprate_type,
            "ip"=>$this->getClientIp(),
            "time"=>time(),
            "time_str"=>date("Y-m-d H:i:s")
        ];
        $v=$this->insert2Mongo($data);
            return response()->json(
                [
                    'code'=>0,
                    'msg'=>'ok',
                    'data'=>$v
                ]
            );
      }
    }
    public function onLiveRoomShareGroup(Request $request){
      $token=$request['token'];
      if($this->validateToken($token)){
        $token=$this->extractToken($token);
        if(empty($token)){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'认证解包异常'
                ]
            );
        }
        $member_id=$token;
        $oprate_type=$request['oprate_type']??'share';
        $room_id=$request['room_id']??null;
        $data=[
            "room_id"=>$room_id,
            "member_id"=>$member_id,
            "oprate_type"=>$oprate_type,
            "ip"=>$this->getClientIp(),
            "time"=>time(),
            "time_str"=>date("Y-m-d H:i:s")
        ];
        $v=$this->insert2Mongo($data);
            return response()->json(
                [
                    'code'=>0,
                    'msg'=>'ok',
                    'data'=>$v
                ]
            );
      }
    }
    private function getClientIp(){
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            return $_SERVER['HTTP_X_FORWARDED_FOR'];
        } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
        return $_SERVER['HTTP_CLIENT_IP'];
        } else {
            return $_SERVER['REMOTE_ADDR'];
        }
    }
    private function insert2Mongo($data){
        $mongo=new Client(env("MONGO_URI",""));
        $db=$mongo->selectDatabase("shop_live");
        $col=$db->selectCollection("event_list");
        return $col->insertOne(
            $data
        )->getInsertedId();
    }
    public function queryLiveRoomStatus(Request $request){
        $member_id=$request['memberid']??null;
        $oprate_type=$request['oprate_type']??'join';
        $room_id=$request['room_id']??null;
        $data=[
            "room_id"=>$room_id,
            "member_id"=>$member_id,
            "oprate_type"=>$oprate_type,
            "ip"=>$this->getClientIp(),
            "time"=>time(),
            "time_str"=>date("Y-m-d H:i:s")
        ];
        $this->insert2Mongo($data);
        $format=$request['format']??'text';
        if(empty($room_id)){
            return null;
        }

        $rooms=ShopController::getLiveRooms();
        $attr='room_'.$room_id;//对象属性需要这个拼凑
        if(!isset($rooms->$attr)){
            if($format=='json')
            return [
                0,0
            ];
            return '0|0';
        }
        $shop_id=$rooms->$attr->shop_id;
        $host_id=$rooms->$attr->host_id;
        $cache_key_list=self::REDIS_PREFIX_GROUP_POINTS."{$shop_id}_{$host_id}_{$room_id}_list";
        $activity=[
            0,0
        ];
        if(Redis::EXISTS($cache_key_list)){
            $activity[0]='1';
        }else{
            $activity[0]='0';
        }
        $begin_time=Redis::GET($cache_key_list.'_begin_time');
        if(empty($begin_time)){
            $activity[1]='0';
        }else{
            $a=($begin_time-time());
            $activity[1]=''.($a<0?0:$a);
        }
        if($format=='text')
        return "{$activity[0]}|{$activity[1]}";
        return
                [
                    'status'=>$activity[0],//1表示获赠进行中，0表示没有活动
                    'countdown'=>$activity[1]//null表示活动已经开始，否则返回具体剩余倒计时
                ];
    }
    private function beforeSendGroupPoints($data){
        $token=$data['token'];
        $cache_key_request=$data['cache_key_request'];
        $cache_key_list=$data['cache_key_list'];
        $shop_id=$data['shop_id'];
        $host_id=$data['host_id'];
        $room_id=$data['room_id'];
        $points=$data['points'];
        $amount=$data['amount'];
        if(Redis::GET($cache_key_request)){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'重复请求'
                ]
            );  
        }
        Redis::SET($cache_key_request,1,'EX',self::REQUEST_API_RATE_TIMEOUT);
        $shop=Redis::EXISTS(Shop::REDIS_PREFIX.$shop_id);
        $host=Redis::EXISTS(ShopHost::REDIS_PREFIX.$host_id);
        if(empty($shop)||empty($host)){
            $shop=Shop::refreshData2Redis($shop_id);
            $host=ShopHost::refreshData2Redis($shop_id,$host_id);
            if(empty($shop)||empty($host))
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'商铺或主播异常'
                ]
            );
        }else{
            $points=intval($points);
            $amount=intval($amount);
            if(empty($points)||empty($amount)||$points<=0||$amount<=0){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'请输入正确数值'
                ]
            );
            }
            $origin_points=ShopHost::getPoints($host_id);
            if($points>$origin_points){
                return response()->json(
                    [
                        'code'=>-1,
                        'msg'=>'积分不足'
                    ]
                );
            }
        }
        if(!$this->validateToken($token)){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'认证异常'
                ]
            );
        }
        $point=bcdiv($points,$amount,2);
        if($point<1){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'平均发送积分需大于1'
                ]
            );
        }
        if(Redis::EXISTS($cache_key_list.'_begin_time')){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'当前积分活动正在进行中'
                ]
            );
        }
        return null;
    }
    public function sendGroupPoints(Request $request){
        $token=$request['token']??null;
        $room_id=$request['room_id']??null;
        $shop_id=$request['shop_id']??null;//可不传 通过roomList进行获取
        $host_id=$request['host_id']??null;//可不传 通过roomList进行获取
        $points=$request['points']??null;
        $amount=$request['amount']??null;
        if(isset($request['test_timelong']))
        $time_long=60;
        else
        $time_long=$request['time_long']??self::POINTS_SEND_LIST_RESET_SECONDS_DELAY;//延时的时长默认60秒
        $countdown_timer=$request['countdown_timer']??10;//延时的时长默认50秒
        $member_size=$request['member_size']??null;// 发放数量需<=房间人数

        $rooms=ShopController::getLiveRooms(true);
        $attr='room_'.$room_id;//对象属性需要这个拼凑
        $attr='room_'.$room_id;//对象属性需要这个拼凑
        if(!isset($rooms->$attr)){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'直播间不存在 no attr',
                    'data'=>$rooms
                ]
            );
        }
        $room_name=$rooms->$attr->title??null;
        if(empty($room_name)){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'直播间不存在 no title',
                    'data'=>$rooms
                ]
            );
        }
        if(empty($shop_id)){
            $shop_id=$rooms->$attr->shop_id;
        }
        if(empty($host_id)){
            $host_id=$rooms->$attr->host_id;
        }
        $cache_key_request=self::REDIS_PREFIX_GROUP_POINTS."{$shop_id}_{$host_id}_{$room_id}_send_{$token}";
        $cache_key_list=self::REDIS_PREFIX_GROUP_POINTS."{$shop_id}_{$host_id}_{$room_id}_list";
        $cache_key_begin_time=$cache_key_list."_begin_time";
        $checker=$this->beforeSendGroupPoints([
            'token'=>$token,
            'room_id'=>$room_id,
            'shop_id'=>$shop_id,
            'host_id'=>$host_id,
            'cache_key_request'=>$cache_key_request,
            'cache_key_list'=>$cache_key_list,
            'points'=>$points,
            'amount'=>$amount
        ]);
        if(!empty($checker)){
            return $checker;
        }
        $point=bcdiv($points,$amount,2);
        //积分领取列表ListKey
        $cache_key_activity_list=self::REDIS_PREFIX_GROUP_POINTS."activity_list";
        $cache_key_grab_list=self::REDIS_PREFIX_GROUP_POINTS."{$shop_id}_{$host_id}_{$room_id}_grab_list";
        $cache_key_activity_current=$cache_key_list."_activity_current";
        $shop=Redis::GET(SHOP::REDIS_PREFIX.$shop_id);
        $host=Redis::GET(ShopHost::REDIS_PREFIX.$host_id);
        $shop=json_decode($shop);//解析JSON
        $host=json_decode($host);//解析JSON
        $shop_name=$shop->origin_name;
        $host_name=$host->origin_name;
        $host_account=$host->origin_account;
        $this->afterSendGroupPoints([
            'token'=>$token,
            'room_id'=>$room_id,
            'room_group_id'=>$rooms->$attr->group_id??null,
            'shop_id'=>$shop_id,
            'host_id'=>$host_id,
            'room_name'=>$room_name,
            'shop_name'=>$shop_name,
            'host_name'=>$host_name,
            'host_account'=>$host_account,
            'cache_key_request'=>$cache_key_request,
            'cache_key_list'=>$cache_key_list,
            'cache_key_begin_time'=>$cache_key_begin_time,
            'cache_key_grab_list'=>$cache_key_grab_list,
            'cache_key_activity_current'=>$cache_key_activity_current,
            'cache_key_activity_list'=>$cache_key_activity_list,
            'points'=>$points,
            'amount'=>$amount,
            'point'=>$point,
            'time_long'=>$time_long,
            'countdown_timer'=>$countdown_timer,
            'oprate_ip'=>$request->getClientIp()
        ]);
        Log::debug("sendGroupPoints[$room_name][$shop_name][$host_name][$points][$amount][$time_long]".PHP_EOL);
        return response()->json(
                [
                    'code'=>0,
                    'msg'=>'success'
                ]
        );  
    }
    private function afterSendGroupPoints($data){
        $this->dispatch(new RunDBCreateJob('points_send_log',$data));
    }
    private function beforeGrabGroupPoints($data){
        $token=$data['token'];
        $room_id=$data['room_id'];
        $room_group_id=$data['room_group_id'];
        $shop_id=$data['shop_id'];
        $host_id=$data['host_id'];
        $cache_key_request=$data['cache_key_request'];
        $cache_key_list=$data['cache_key_list'];
        $cache_key_grab_list=$data['cache_key_grab_list'];
        //$is_subscribe_host_key=sprintf("site:subscribe:%s:%s",$shop_id,$token);

        if(Redis::GET($cache_key_request)){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'重复请求'
                ]
            );  
        }
        Redis::SET($cache_key_request,1,'EX',self::REQUEST_API_RATE_TIMEOUT);
        $shop=Redis::EXISTS(Shop::REDIS_PREFIX.$shop_id);
        $host=Redis::EXISTS(ShopHost::REDIS_PREFIX.$host_id);
        if(empty($shop)||empty($host)){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'商铺或主播异常'
                ]
            );
        }
        if(!$this->validateToken($token)){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'认证异常'
                ]
            );
        }
        if(env('ALLENAPI_CHECK_SUBSCRIBE',false)&&ShopMemberModel::isSubscribeMe($shop_id,$token)){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'请先关注商铺'
                ]
            );
        }
        if(!Redis::EXISTS($cache_key_list)){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'暂无积分活动'
                ]
            );
        }
        if(empty(Redis::LLEN($cache_key_list))){
                            if(!env('API_TEST')&&!empty($room_group_id))
                            LiveGroupModel::sendGroupMsg($room_group_id,[
                                'code' => 0,
                                'type' => 'no_points',
                                'data'=>null]);
                                else{
                                    Log::debug("测试不群发{$room_group_id}\r\n");
                                }
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'很遗憾，您和积分插肩而过'
                ]
            );
        }
        $begin_time=Redis::GET($cache_key_list.'_begin_time');
        $less=$begin_time-time();
        if($less>0){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'活动倒计时中'
                ]
            );
        }
        if(Redis::EXISTS($cache_key_grab_list)&&!empty(Redis::SISMEMBER($cache_key_grab_list,$token))){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'积分已派发至您账户'
                ]
            );
        }
        return null;
    }
    public function grabGroupPoints(Request $request){
        $token=$request['token']??null;
        if(empty($token)){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'认证解包异常'
                ]
            );
        }
        //识别抽取TOKEN人员标识
        $token=$this->extractToken($token);
        if(empty($token)){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'认证解包异常'
                ]
            );
        }
        $room_id=$request['room_id']??null;
        $shop_id=$request['shop_id']??null;
        $host_id=$request['host_id']??null;
        $rooms=ShopController::getLiveRooms();
        $attr='room_'.$room_id;//对象属性需要这个拼凑
        if(!isset($rooms->$attr)){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'直播间不存在'
                ]
            );
        }
        $room_name=$rooms->$attr->title??null;
        $room_group_id=$rooms->$attr->group_id??null;
        if(empty($room_name)){
            return response()->json(
                [
                    'code'=>-1,
                    'msg'=>'异常直播间'
                ]
            );
        }
        if(empty($shop_id)){
            $shop_id=$rooms->$attr->shop_id;
        }
        if(empty($host_id)){
            $host_id=$rooms->$attr->host_id;
        }
        $cache_key_request=self::REDIS_PREFIX_GROUP_POINTS."{$shop_id}_{$host_id}_{$room_id}_grab_{$token}";
        $cache_key_list=self::REDIS_PREFIX_GROUP_POINTS."{$shop_id}_{$host_id}_{$room_id}_list";
        $cache_key_total=$cache_key_list.'_total';
        $cache_key_activity_current=$cache_key_list."_activity_current";
        $activity_id=Redis::GET($cache_key_activity_current);
        //积分领取列表ListKey
        $cache_key_grab_list=self::REDIS_PREFIX_GROUP_POINTS."{$shop_id}_{$host_id}_{$room_id}_grab_list_".$activity_id;
        $checker=$this->beforeGrabGroupPoints([
            'token'=>$token,
            'room_id'=>$room_id,
            'room_group_id'=>$room_group_id,
            'shop_id'=>$shop_id,
            'host_id'=>$host_id,
            'cache_key_request'=>$cache_key_request,
            'cache_key_list'=>$cache_key_list,
            'cache_key_grab_list'=>$cache_key_grab_list
        ]);
        if(!empty($checker)){
            return $checker;
        }
        $tokenName=$token;
        $points=Redis::GET($cache_key_total);//总发放积分//这也是检测条件之一！
        $point=Redis::GET($cache_key_list.'_average');//这也是检测条件之一！
        $shop=Redis::GET(Shop::REDIS_PREFIX.$shop_id);
        $host=Redis::GET(ShopHost::REDIS_PREFIX.$host_id);
        $shop=json_decode($shop);//解析JSON
        $host=json_decode($host);//解析JSON
        $shop_name=$shop->origin_name;
        $host_name=$host->origin_name;
        $attr='room_'.$room_id;
        $room_name=$roomList->$attr->title??null;
        $this->afterGrabGroupPoints([
            'activity_id'=>$activity_id,
            'token'=>$token,
            'room_id'=>$room_id,
            'shop_id'=>$shop_id,
            'host_id'=>$host_id,
            'shop_name'=>$shop_name,
            'host_name'=>$host_name,
            'room_name'=>$room_name,
            'receive_id'=>$token,
            'receive_name'=>$tokenName,
            'points'=>$points,
            'cache_key_request'=>$cache_key_request,
            'cache_key_list'=>$cache_key_list,
            'cache_key_grab_list'=>$cache_key_grab_list,
            'oprate_ip'=>$request->getClientIp()
        ]);
        return response()->json(
                [
                    'code'=>0,
                    'msg'=>'success',
                    'data'=>$point
                ]
        );  
    }
    private function afterGrabGroupPoints($data){
        $this->dispatch(new RunDBCreateJob('points_receive_log',$data));

    }
    //
    public function getRoomMemberList(Request $request){
        $appid="1600103678";
        $admin="administrator";
        $adminsecret="eJwtzEELgjAcBfDvsuvC-s42U*hQ0SGpkAwP0UXYkj*lzm1kEH33TD2*33u8D7kcMu*lDIkJ84DMhoxS1Q7vOHAhK6zROlO4xkwDKx*F1ihJ7AsAHwIRLsdGvTUa1TvnnAHAqA6rv4VcLALuMz69YNn-q62iqX2Gt7kp8chyur*e9Tqq26RraBZs0jY67ZI2ZwnrVuT7A4FyNJA_";
        $randnum=mt_rand(1,999999);
        $roomid=$request['roomid']??null;
        if(empty($roomid)){
            return 'null';
        }
        $url="https://console.tim.qq.com/v4/group_open_avchatroom_http_svc/get_members?sdkappid=%s&identifier=%s&usersig=%s&random=%s&contenttype=json";
        $url=sprintf($url,$appid,$admin,$adminsecret,$randnum);
        $data=[
                "GroupId"=>$roomid,
                "Timestamp"=> 0
        ];
        $http=Http::post($url,$data);
        $res=$http->json();
        return $res;
    }
    public function getRoomMemberSize(Request $request){
        $roomid=$request['roomid']??null;
        if(empty($roomid)){
            return [];
        }
        $appid="1600103678";
        $admin="administrator";
        $adminsecret="eJwtzEELgjAcBfDvsuvC-s42U*hQ0SGpkAwP0UXYkj*lzm1kEH33TD2*33u8D7kcMu*lDIkJ84DMhoxS1Q7vOHAhK6zROlO4xkwDKx*F1ihJ7AsAHwIRLsdGvTUa1TvnnAHAqA6rv4VcLALuMz69YNn-q62iqX2Gt7kp8chyur*e9Tqq26RraBZs0jY67ZI2ZwnrVuT7A4FyNJA_";
        $randnum=mt_rand(1,999999);
        $roomid=$request['roomid']??null;
        if(empty($roomid)){
            return 'null';
        }
        $url="https://console.tim.qq.com/v4/group_open_http_svc/get_online_member_num?sdkappid=%s&identifier=%s&usersig=%s&random=%s&contenttype=json";
        $url=sprintf($url,$appid,$admin,$adminsecret,$randnum);
        $data=[
                "GroupId"=>$roomid,
        ];
        $http=Http::post($url,$data);
        $res=$http->json();
        return $res;
    }
    public function incRobot2Room(Request $request){
        $appid="1600103678";
        $admin="administrator";
        $adminsecret="eJwtzEELgjAcBfDvsuvC-s42U*hQ0SGpkAwP0UXYkj*lzm1kEH33TD2*33u8D7kcMu*lDIkJ84DMhoxS1Q7vOHAhK6zROlO4xkwDKx*F1ihJ7AsAHwIRLsdGvTUa1TvnnAHAqA6rv4VcLALuMz69YNn-q62iqX2Gt7kp8chyur*e9Tqq26RraBZs0jY67ZI2ZwnrVuT7A4FyNJA_";
        $randnum=mt_rand(1,999999);
        $roomid=$request['roomid']??null;
        if(empty($roomid)){
            return [];
        }
        $url="https://console.tim.qq.com/v4/openim_robot_http_svc/create_robot?sdkappid=%s&identifier=%s&usersig=%s&random=%s&contenttype=json";
        $url=sprintf($url,$appid,$admin,$adminsecret,$randnum);   
        $idlist=[];
        for($i=0;$i<10;$i++){
            $id=($i+1);
            $userid="@RBT#000".$id;     
            $data=[
        "UserID"=>$userid,
        "Nick"=> "Robot".$id,
        "FaceUrl"=>"https://pnpm.io/zh/img/pnpm-no-name-with-frame.svg",
        "SelfSignature"=> "Robot hello, world".$id,
            ];
            $http=Http::post($url,$data);
            $makeRobotRes=$http->json();
            if($makeRobotRes['ActionStatus']=='OK'){
                $idlist[]=$userid;
            }
        }
        $res=[];
        if(!empty($idlist))
        $res=$this->addRobot2Room($roomid,$idlist);
        return compact('userid','idlist','res','makeRobotRes');
    }
    public function addRobot2Room(Request $request){
        $robotidlist=$request['robotidlist'];
        $appid="1600103678";
        $admin="administrator";
        $adminsecret="eJwtzEELgjAcBfDvsuvC-s42U*hQ0SGpkAwP0UXYkj*lzm1kEH33TD2*33u8D7kcMu*lDIkJ84DMhoxS1Q7vOHAhK6zROlO4xkwDKx*F1ihJ7AsAHwIRLsdGvTUa1TvnnAHAqA6rv4VcLALuMz69YNn-q62iqX2Gt7kp8chyur*e9Tqq26RraBZs0jY67ZI2ZwnrVuT7A4FyNJA_";
        $randnum=mt_rand(1,999999);
        $roomid=$request['roomid']??null;
        if(empty($roomid)){
            return [];
        }
        $url="https://console.tim.qq.com/v4/group_open_avchatroom_http_svc/add_robots?sdkappid=%s&identifier=%s&usersig=%s&random=%s&contenttype=json";
        $url=sprintf($url,$appid,$admin,$adminsecret,$randnum);   
        $id=mt_rand(1,100);
        $userid="@RBT#000".$id;     
        $data=[
    "GroupId"=>$roomid,
    "Member_Account"=>$robotidlist,
        ];
        $http=Http::post($url,$data);
        $res=$http->json();
        return $res;
    }
    public function delRobot2Room(Request $request){
        $robotidlist=$request['robotidlist'];
        $appid="1600103678";
        $admin="administrator";
        $adminsecret="eJwtzEELgjAcBfDvsuvC-s42U*hQ0SGpkAwP0UXYkj*lzm1kEH33TD2*33u8D7kcMu*lDIkJ84DMhoxS1Q7vOHAhK6zROlO4xkwDKx*F1ihJ7AsAHwIRLsdGvTUa1TvnnAHAqA6rv4VcLALuMz69YNn-q62iqX2Gt7kp8chyur*e9Tqq26RraBZs0jY67ZI2ZwnrVuT7A4FyNJA_";
        $randnum=mt_rand(1,999999);
        $roomid=$request['roomid']??null;
        if(empty($roomid)){
            return [];
        }
        $url="https://console.tim.qq.com/v4/group_open_avchatroom_http_svc/del_robots?sdkappid=%s&identifier=%s&usersig=%s&random=%s&contenttype=json";
        $url=sprintf($url,$appid,$admin,$adminsecret,$randnum);   
        $id=mt_rand(1,100);
        $userid="@RBT#000".$id;     
        $data=[
    "GroupId"=>$roomid,
    "Member_Account"=>$robotidlist,
        ];
        $http=Http::post($url,$data);
        $res=$http->json();
        return $res;
    }
}
